/*package com.smarttest.portal.service.timertask;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import javax.annotation.PostConstruct;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.smarttest.portal.service.RangeStopCountService;

@Service
public class RangeEventTimer {

	@Value("${runtimertask:false}")
	private String runtimertask = "false";
	@Value("${rangeruntime}")
	private String rangeruntime;
	

	private static final Logger log = Logger.getLogger(RangeEventTimer.class);
	private ScheduledExecutorService scheduledExecutorService = Executors
			.newSingleThreadScheduledExecutor();

	@Autowired
	RangeRefreshMonitor rangeRefreshMonitor;
	@Autowired
	RangeStopCountService rangeStopCountService;

	@PostConstruct
	public void init() {
		if (StringUtils.equalsIgnoreCase("true", runtimertask)) {
			log.info("RangeEventCount init-" + Thread.currentThread().getName());
			long oneDay = 24 * 60 * 60 * 1000;
			long initDelay = getTimeMillis(rangeruntime)
					- System.currentTimeMillis();
			initDelay = initDelay > 0 ? initDelay : oneDay + initDelay;
			scheduledExecutorService.scheduleWithFixedDelay(new Runnable() {

				@Override
				public void run() {
					rangeEventCount();
				}
			}, initDelay, oneDay, TimeUnit.MILLISECONDS);
		}
	}

	private long getTimeMillis(String time) {
		Calendar c = Calendar.getInstance();
		String day = new SimpleDateFormat("yyyyMMdd").format(c.getTime());

		day = day + time;
		try {
			return new SimpleDateFormat("yyyyMMddHH:mm:ss").parse(day)
					.getTime();
		} catch (ParseException e) {
			e.printStackTrace();
			log.error("error day:" + day);
			return 0;
		}
	}
	private void rangeEventCount() {
		DateTime dt = new DateTime();
		DateTime yesterday = dt.minusDays(1);
		String strStart = yesterday.toString("yyyy-MM-dd 00:00:00");
		String strEnd = yesterday.toString("yyyy-MM-dd 23:59:59");
		DateTimeFormatter format = DateTimeFormat
				.forPattern("yyyy-MM-dd HH:mm:ss");
		DateTime dateStart = DateTime.parse(strStart, format);
		DateTime dateEnd = DateTime.parse(strEnd, format);
		Date startTime = dateStart.toDate();
		Date endTime = dateEnd.toDate();
		
		

		JSONObject json = rangeRefreshMonitor.getAllRangeEvent(startTime,endTime);
		int rangeInBefore = json.getIntValue("RangeInBefore");
		int rangeInAfter = json.getIntValue("RangeInAfter");
		int rangeOutBefore = json.getIntValue("RangeOutBefore");
		int rangeOutAfter = json.getIntValue("RangeOutAfter");
		
		
		Date dbStart = new Date();
		dbStart.setHours(0);
		dbStart.setMinutes(0);
		dbStart.setSeconds(0);
		
		Date dbEnd = new Date();
		dbEnd.setHours(23);
		dbEnd.setMinutes(59);
		dbEnd.setSeconds(59);
		
		rangeStopCountService.saveEvent(10, rangeInBefore, rangeInAfter,dbStart,dbEnd);
		rangeStopCountService.saveEvent(11, rangeOutBefore, rangeOutAfter,dbStart,dbEnd);
	}
	
}
*/